package com.ubing.boot.notesforjava.test.juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class _1TO52ATOZ {
    private Lock lock=new ReentrantLock();
    private Condition _1To52=lock.newCondition();
    private Condition _AToZ=lock.newCondition();
    private Integer number=1;
    private Integer number2=2;
    private char ch='A';

    private void _1To52(){
        while (number2<=52){
        lock.lock();
        try {
                System.out.print(number+""+number2);
                number+=2;
                number2+=2;
                _AToZ.signalAll();
            _1To52.await();

        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }finally {
            lock.unlock();
        }
        }

    }

    private void _AToZ(){
        while (ch<='Z'){
        lock.lock();
        try {
                System.out.print(ch);
                ch++;
                _1To52.signalAll();
            _AToZ.await();

        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }finally {
            lock.unlock();
        }
        }

    }


    public static void main(String[] args) {
        _1TO52ATOZ to52ATOZ = new _1TO52ATOZ();
//        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                to52ATOZ._1To52();
            }).start();
            new Thread(()->{
                to52ATOZ._AToZ();
            }).start();
//        }

    }
}
